#!/bin/sh
# 

SCRIPT=`readlink -f "$0"`
P=`dirname "$SCRIPT"` # $P/$0
cd $P


CC="../../cc.sh"

GM="../../gm/lsfr.pwn"

for i in `cat gamemodes/states.txt`
do
  NAME=`echo $i | awk -F':' '{print $1}'`
  MOD=`echo $i | awk -F':' '{print $2}'`
  PORT=`echo $i | awk -F':' '{print $3}'`
  SHORT=`echo $i | awk -F':' '{print $4}'`
  echo "compiling $NAME..."
  if [ -r gamemodes/prefix.txt ]
  then
    cp -f gamemodes/prefix.txt prefix.tmp
  fi
  touch prefix.tmp
  echo "#define MOD_CURRENT $MOD" >> prefix.tmp
  if [ ! -d $NAME ]
  then
    mkdir $NAME
  elif [ -r $NAME/prefix.txt ]
  then
    cat $NAME/prefix.txt >> prefix.tmp
  fi
  $CC $GM $* -pprefix.tmp "-o$NAME/lsfr.amx"
  rm prefix.tmp


  echo "proccessing config file..."
  gcc -E -P -x c++ -DPORT=$PORT -DNAME=$NAME -DSHORT=$SHORT -DREV=`svnversion -n ./` -DMOD=$MOD server.cfg | sed '/^$/d' > "serv${SHORT}.cfg"
done

